<?php
/***
* @version $Id: install.php 336 2007-01-23 08:12:56Z flexiondotorg $
* @copyright (c) 2006 - 2007 Flexion.Org
*            (c) 2004 - 2005 geocator < geocator@gmail.com > (Brian) http://www.geocator.us
*            (c) 2004 - 2005 Project Minerva
*            (c) 2001 - 2006 phpBB Group
* @license   http://opensource.org/licenses/gpl-license.php GNU Public License
***/

define('IN_R3BORN', true);

// Error reporting level and runtime escaping
error_reporting(E_ERROR | E_WARNING | E_PARSE);

@set_time_limit(120);

// Include essential scripts
$root_path = './../';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
require($root_path . 'includes/functions.'.$phpEx);
require($root_path . 'includes/functions_install.'.$phpEx);
include($root_path . 'includes/functions_sessions.'.$phpEx);

/*
* Remove variables created by register_globals from the global scope
* Thanks to Matt Kavanagh
*/
function deregister_globals()
{
	$not_unset = array(
		'GLOBALS' => true,
		'_GET' => true,
		'_POST' => true,
		'_COOKIE' => true,
		'_REQUEST' => true,
		'_SERVER' => true,
		'_SESSION' => true,
		'_ENV' => true,
		'_FILES' => true,
		'phpEx' => true,
		'root_path' => true,
		'mvModule_root_path' => true,
		'mvModuleName' => true
	);

	// Not only will array_merge and array_keys give a warning if
	// a parameter is not an array, array_merge will actually fail.
	// So we check if _SESSION has been initialised.
	if (!isset($_SESSION) || !is_array($_SESSION))
	{
		$_SESSION = array();
	}

	// Merge all into one extremely huge array; unset
	// this later
	$input = array_merge(
		array_keys($_GET),
		array_keys($_POST),
		array_keys($_COOKIE),
		array_keys($_SERVER),
		array_keys($_SESSION),
		array_keys($_ENV),
		array_keys($_FILES)
	);

	foreach ($input as $varname)
	{
		if (isset($not_unset[$varname]))
		{
			// Hacking attempt. No point in continuing.
			die('Hacking attempt');
		}
		unset($GLOBALS[$varname]);
	}
	unset($input);
}

function array_addslashes(&$array)
{
	foreach ($array as $k => $v)
	{
		if ( is_array($array[$k]))
		{
			array_addslashes($array[$k]);
		}
		else
		{
			$array[$k] = addslashes($v);
		}
	}
}

// If we are not on PHP >= 6.0.0 we do not need to run some code
if (!version_compare(phpversion(), '6.0.0-dev', '>='))
{
	set_magic_quotes_runtime(0);

	// Be paranoid with passed vars
	if (@ini_get('register_globals') == '1' || strtolower(@ini_get('register_globals')) == 'on')
	{
		deregister_globals();
	}
}

if (!get_magic_quotes_gpc())
{
	// None of these are conditionaly set.
	/*
	array_addslashes($HTTP_GET_VARS);
	array_addslashes($HTTP_POST_VARS);
	array_addslashes($HTTP_COOKIE_VARS);
	*/

	array_addslashes($_GET);
	array_addslashes($_POST);
	array_addslashes($_COOKIE);
	array_addslashes($_REQUEST);
}

// Initialise some basic arrays
$userdata = array();
$lang = array();

// Try opening config file
if (@file_exists($root_path . 'config.'.$phpEx))
{
	include($root_path . 'config.'.$phpEx);

	if (defined('R3BORN_INSTALLED'))
	{
		redirect("../index.$phpEx");
	}
}

// Obtain various vars
$stage = get_var('stage', 0);

//, 'acm_type'
// These are all strings so we'll just traverse an array
$var_ary = array('language', 'dbms', 'dbhost', 'dbport', 'dbuser', 'dbpasswd', 'dbname', 'table_prefix', 'admin_name', 'admin_pass1', 'admin_pass2', 'board_email1', 'board_email2', 'server_name', 'server_port', 'script_path', 'img_imagick', 'ftp_path', 'ftp_user', 'ftp_pass', 'cookie_secure', 'cookie_domain', 'cookie_name', 'cookie_path');

foreach ($var_ary as $var)
{
	$$var = get_var($var, '');
}

$error = array();

// Other PHP modules we may find useful
//$php_dlls_other	= array('zlib', 'mbstring', 'ftp');
$php_dlls_other	= array('zlib', 'ftp', 'xml', 'gd');

$suffix = ((defined('PHP_OS')) && (preg_match('#win#i', PHP_OS))) ? 'dll' : 'so';


//
// Variables defined ... start program proper
//


// Try and load an appropriate language if required

// Guess an initial language ... borrowed from phpBB 2.2 it's not perfect,
// really it should do a straight match first pass and then try a "fuzzy"
// match on a second pass instead of a straight "fuzzy" match.
function guess_lang()
{
	global $root_path, $HTTP_SERVER_VARS;

// The order here _is_ important, at least for major_minor
// matches. Don't go moving these around without checking with
// me first - psoTFX
$match_lang = array(
	'arabic'					=> 'ar([_-][a-z]+)?',
	'bulgarian'					=> 'bg',
	'catalan'					=> 'ca',
	'czech'						=> 'cs',
	'danish'					=> 'da',
	'german'					=> 'de([_-][a-z]+)?',
	'english'					=> 'en([_-][a-z]+)?',
	'estonian'					=> 'et',
	'finnish'					=> 'fi',
	'french'					=> 'fr([_-][a-z]+)?',
	'greek'						=> 'el',
	'spanish_argentina'			=> 'es[_-]ar',
	'spanish'					=> 'es([_-][a-z]+)?',
	'gaelic'					=> 'gd',
	'galego'					=> 'gl',
	'gujarati'					=> 'gu',
	'hebrew'					=> 'he',
	'hindi'						=> 'hi',
	'croatian'					=> 'hr',
	'hungarian'					=> 'hu',
	'icelandic'					=> 'is',
	'indonesian'				=> 'id([_-][a-z]+)?',
	'italian'					=> 'it([_-][a-z]+)?',
	'japanese'					=> 'ja([_-][a-z]+)?',
	'korean'					=> 'ko([_-][a-z]+)?',
	'latvian'					=> 'lv',
	'lithuanian'				=> 'lt',
	'macedonian'				=> 'mk',
	'dutch'						=> 'nl([_-][a-z]+)?',
	'norwegian'					=> 'no',
	'punjabi'					=> 'pa',
	'polish'					=> 'pl',
	'portuguese_brazil'			=> 'pt[_-]br',
	'portuguese'				=> 'pt([_-][a-z]+)?',
	'romanian'					=> 'ro([_-][a-z]+)?',
	'russian'					=> 'ru([_-][a-z]+)?',
	'slovenian'					=> 'sl([_-][a-z]+)?',
	'albanian'					=> 'sq',
	'serbian'					=> 'sr([_-][a-z]+)?',
	'slovak'					=> 'sv([_-][a-z]+)?',
	'swedish'					=> 'sv([_-][a-z]+)?',
	'thai'						=> 'th([_-][a-z]+)?',
	'turkish'					=> 'tr([_-][a-z]+)?',
	'ukranian'					=> 'uk([_-][a-z]+)?',
	'urdu'						=> 'ur',
	'viatnamese'				=> 'vi',
	'chinese_traditional_taiwan'=> 'zh[_-]tw',
	'chinese_simplified'		=> 'zh',
);

if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE']))
{
	$accept_lang_ary = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);

	for ($i = 0; $i < sizeof($accept_lang_ary); $i++)
	{
		@reset($match_lang);
		while (list($lang, $match) = each($match_lang))
		{
			if (preg_match('#' . $match . '#i', trim($accept_lang_ary[$i])))
			{

				if (file_exists(@realpath($root_path . 'language/lang_' . $lang)))
				{
					//$language = $lang;
					return $lang;
				}
			}
		}
	}
}

//$language = 'english';
return 'english';
}

$language = guess_lang();

include($root_path . 'language/lang_' . $language . '/lang_main.'.$phpEx);
include($root_path . 'language/lang_' . $language . '/lang_admin.'.$phpEx);
include($root_path . 'language/lang_' . $language . '/lang_install.'.$phpEx);

// Here we do a number of tests and where appropriate reset the installation level
// depending on the outcome of those tests. It's perhaps a little clunky but
// it means we have a fairly clear and logical path through the installation and
// this source ... well, till I go and fill it with fudge
if (isset($_POST['retest']))
{
	$stage = 0;
}
else if (isset($_POST['testdb']))
{
	$stage = 1;
}
else if (isset($_POST['install']))
{
	// Check for missing data
	$var_ary = array(
		'admin'		=> array('admin_name', 'admin_pass1', 'admin_pass2', 'board_email1', 'board_email2'),
		'server'	=> array('server_name', 'server_port', 'script_path'),
		'cookie'	=> array('cookie_name', 'cookie_path')
	);

	foreach ($var_ary as $var_type => $var_block)
	{
		foreach ($var_block as $var)
		{
			if (!$$var)
			{
				$error[$var_type][] = $lang['INST_ERR_MISSING_DATA'];
				break;
			}
		}
	}

	// Check the entered email address and password
	if ($admin_pass1 != $admin_pass2 && $admin_pass1 != '')
	{
		$error['admin'][] = $lang['INST_ERR_PASSWORD_MISMATCH'];
	}

	if ($board_email1 != $board_email2 && $board_email1 != '')
	{
		$error['admin'][] = $lang['INST_ERR_EMAIL_MISMATCH'];
	}

	// Test the database connectivity
	if (!@extension_loaded($available_dbms[$dbms]['MODULE']))
	{
		if (!can_load_dll($available_dbms[$dbms]['MODULE']))
		{
			$error['db'][] = $lang['INST_ERR_NO_DB'];
		}
	}

	connect_check_db(false, $error, $dbms, $table_prefix, $dbhost, $dbuser, $dbpasswd, $dbname, $dbport);

	// No errors so lets do the twist
	if (sizeof($error))
	{
		$stage = 1;
	}
}
else if (isset($_POST['dldone']))
{
	// A minor fudge ... we're basically trying to see if the user uploaded
	// their downloaded config file ... it's not worth IMO trying to
	// open it and compare all the data. If a user wants to screw up this
	// simple task ... well ... uhm
	if (filesize($root_path . 'config.'.$phpEx) < 10)
	{
		$stage = 2;
	}
	else
	{
		$stage = 3;
	}
}


// Zero stage of installation
//
// Here we basically imform the user of any potential issues such as no database
// support, missing directories, etc. We also give some insight into "missing"
// modules which we'd quite like installed (but which are not essential)
if ($stage == 0)
{
	// Test for DB modules
	$dlls_db = array();
	$passed['db'] = false;
	foreach ($available_dbms as $db_name => $db_ary)
	{
		$dll = $db_ary['MODULE'];

		if (!extension_loaded($dll))
		{
			if (!can_load_dll($dll))
			{
				$dlls_db[$db_name] = '<b style="color:red">' . $lang['UNAVAILABLE'] . '</b>';
				continue;
			}
		}
		$dlls_db[$db_name] = '<b style="color:green">' . $lang['AVAILABLE'] . '</b>';
		$passed['db'] = true;
	}

	// Test for other modules
	$dlls_other = array();
	foreach ($php_dlls_other as $dll)
	{
		if (!extension_loaded($dll))
		{
			if (!can_load_dll($dll))
			{
				$dlls_other[$dll] = '<b style="color:red">' . $lang['UNAVAILABLE'] . '</b>';
				continue;
			}
		}
		$dlls_other[$dll] = '<b style="color:green">' . $lang['AVAILABLE'] . '</b>';
	}

	inst_page_header($lang['WELCOME_INSTALL']);

?>
<form action="<?php echo "install.$phpEx"; ?>" name="installation" method="post">
<h1><?php echo $lang['INSTALL_INTRO']; ?></h1>

<p><?php echo $lang['INSTALL_INTRO_BODY']; ?></p>

<hr />

<h1><?php echo $lang['PHP_SETTINGS']; ?></h1>

<h2><?php echo $lang['REQUIREMENTS_TITLE']; ?></h2>

<p><?php echo $lang['REQUIREMENTS_EXPLAIN']; ?></p>

<table width="100%" cellspacing="1" cellpadding="2" border="0" class="forumline">
	<tr>
		<td>&bull;&nbsp;<b><?php echo $lang['PHP_VERSION_REQD']; ?>: </b></td>
		<td><?php

	$php_version = phpversion();

	if (version_compare($php_version, '4.2.0') < 0)
	{
		$passed['db'] = false;
		echo '<b style="color:red">' . $lang['No'] . '</b>';
	}
	else
	{
		// We also give feedback on whether we're running in safe mode
		echo '<b style="color:green">' . $lang['Yes'];
		if (@ini_get('safe_mode') || strtolower(@ini_get('safe_mode')) == 'on')
		{
			echo ', ' . $lang['PHP_SAFE_MODE'];
		}
		echo '</b>';
	}

?></td>
	</tr>
	<tr>
		<td width="50%">&bull;&nbsp;<b><?php echo $lang['PHP_REGISTER_GLOBALS']; ?>: </b></td>
		<td width="50%"><?php
	if (@ini_get('register_globals') == '1' || strtolower(@ini_get('register_globals')) == 'on')
	{
		echo '<b style="color:red">' . $lang['No'] . '</b>';
	}
	else
	{
		echo '<b style="color:green">' . $lang['Yes'] . '</b>';
	}
?></td>
	</tr>
	<tr>
		<td rowspan="<?php echo sizeof($dlls_db); ?>" valign="top">&bull;&nbsp;<b><?php echo $lang['PHP_SUPPORTED_DB']; ?>: </b></td>
<?php

	$i = 0;
	foreach ($dlls_db as $dll => $available)
	{
		echo ($i++ > 0) ? '<tr>' : '';

?>
		<td width="50%"><?php echo $lang['DLL_' . strtoupper($dll)]; ?> </td>
		<td width="50%"><?php echo $available; ?></td>
	</tr>
<?php

	}

?>
</table>

<h2><?php echo $lang['PHP_OPTIONAL_MODULE']; ?></h2>

<p><?php echo $lang['PHP_OPTIONAL_MODULE_EXPLAIN']; ?></p>

<table width="100%" cellspacing="1" cellpadding="2" border="0" class="forumline">
	<tr>
<?php

	// Optional modules which may be useful to us
	foreach ($dlls_other as $dll => $yesno)
	{

?>
	<tr>
		<td width="50%">&bull;&nbsp;<b><?php echo $lang['DLL_' . strtoupper($dll)]; ?>: </b></td>
		<td width="50%"><?php echo $yesno; ?></td>
	</tr>
<?php

	}

	$exe = ((defined('PHP_OS')) && (preg_match('#win#i', PHP_OS))) ? '.exe' : '';

	$magic_home = getenv('MAGICK_HOME');

	// Imagemagick are you there? Give me a sign or a path ...
	$img_imagick = '';
	if (empty($magic_home))
	{
		$locations = array('C:/WINDOWS/', 'C:/WINNT/', 'C:/WINDOWS/SYSTEM/', 'C:/WINNT/SYSTEM/', 'C:/WINDOWS/SYSTEM32/', 'C:/WINNT/SYSTEM32/', '/usr/bin/', '/usr/sbin/', '/usr/local/bin/', '/usr/local/sbin/', '/opt/', '/usr/imagemagick/', '/usr/bin/imagemagick/');
		$path_locations = str_replace('\\', '/', (explode(($exe) ? ';' : ':', getenv('PATH'))));

		$locations = array_merge($path_locations, $locations);
		foreach ($locations as $location)
		{
			// The path might not end properly, fudge it
			if (substr($location, -1, 1) !== '/')
			{
				$location .= '/';
			}

			if (@is_readable($location . 'mogrify' . $exe) && @filesize($location . 'mogrify' . $exe) > 3000)
			{
				$img_imagick = str_replace('\\', '/', $location);
				continue;
			}
		}
	}
	else
	{
		$img_imagick = str_replace('\\', '/', $magic_home);
	}

?>
	<tr>
		<td width="50%">&bull;&nbsp;<b><?php echo $lang['APP_MAGICK']; ?>: </b></td>
		<td width="50%"><?php echo ($img_imagick) ? '<b style="color:green">' . $lang['AVAILABLE'] . ', ' . $img_imagick . '</b>' : '<b style="color:blue">' . $lang['NO_LOCATION'] . '</b>'; ?></td>
	</tr>
</table>

<h1 align="center" <?php echo ($passed['db']) ? 'style="color:green">' . $lang['TESTS_PASSED'] : 'style="color:red">' . $lang['TESTS_FAILED']; ?></h2>

<hr />

<h1><?php echo $lang['DIRECTORIES_AND_FILES']; ?></h2>

<h2><?php echo $lang['FILES_REQUIRED']; ?></h2>

<p><?php echo $lang['FILES_REQUIRED_EXPLAIN']; ?></p>

<table width="100%" cellspacing="1" cellpadding="2" border="0" class="forumline">
<?php

	$directories = array('cache/', 'files/', 'files/avatars/');

	umask(0);

	$passed['files'] = true;
	foreach ($directories as $dir)
	{
		$write = $exists = true;
		if (file_exists($root_path . $dir))
		{
			if (!is_writeable($root_path . $dir))
			{
				$write = (@chmod($root_path . $dir, 0777)) ? true : false;
			}
		}
		else
		{
			$write = $exists = (@mkdir($root_path . $dir, 0777)) ? true : false;
		}

		$passed['files'] = ($exists && $write && $passed['files']) ? true : false;

		$exists = ($exists) ? '<b style="color:green">' . $lang['FILE_FOUND'] . '</b>' : '<b style="color:red">' . $lang['FILE_NOT_FOUND'] . '</b>';
		$write = ($write) ? ', <b style="color:green">' . $lang['FILE_WRITEABLE'] . '</b>' : (($exists) ? ', <b style="color:red">' . $lang['FILE_UNWRITEABLE'] . '</b>' : '');

?>
	<tr>
		<td width="50%">&bull;&nbsp;<b><?php echo $dir; ?></b></td>
		<td width="50%"><?php echo $exists . $write; ?></td>
	</tr>
<?php

	}

?>
</table>

<h2><?php echo $lang['FILES_OPTIONAL']; ?></h2>

<p><?php echo $lang['FILES_OPTIONAL_EXPLAIN']; ?></p>

<table width="100%" cellspacing="1" cellpadding="2" border="0" class="forumline">
<?php

	// config.php ... let's just warn the user it's not writeable
	$dir = 'config.'.$phpEx;
	$write = $exists = true;
	if (file_exists($root_path . $dir))
	{
		if (!is_writeable($root_path . $dir))
		{
			$write = false;
		}
	}
	else
	{
		$write = $exists = false;
	}

	$exists = ($exists) ? '<b style="color:green">' . $lang['FILE_FOUND'] . '</b>' : '<b style="color:red">' . $lang['FILE_NOT_FOUND'] . '</b>';
	$write = ($write) ? ', <b style="color:green">' . $lang['FILE_WRITEABLE'] . '</b>' : (($exists) ? ', <b style="color:red">' . $lang['FILE_UNWRITEABLE'] . '</b>' : '');

?>
	<tr>
		<td width="50%">&bull;&nbsp;<b><?php echo $dir; ?></b></td>
		<td width="50%"><?php echo $exists . $write; ?></td>
	</tr>
</table>

<h1 align="center" <?php echo ($passed['files']) ? 'style="color:green">' . $lang['TESTS_PASSED'] : 'style="color:red">' . $lang['TESTS_FAILED']; ?></h2>

<hr />

<h1><?php echo $lang['INSTALL_NEXT']; ?></h1>

<?php

	$next_text = ($passed['db'] && $passed['files']) ? $lang['INSTALL_NEXT_PASS'] : $lang['INSTALL_NEXT_FAIL'];

	$s_hidden_fields = ($img_imagick) ? '<input type="hidden" name="img_imagick" value="' . addslashes($img_imagick) . '" />' : '';

?>

<p><?php echo $next_text; ?></p>

<table width="100%" cellspacing="1" cellpadding="2" border="0">
	<tr>
		<td colspan="2" align="center"><?php echo $s_hidden_fields; ?><input type="hidden" name="stage" value="1" /><input class="liteoption" name="retest" type="submit" value="<?php echo $lang['INSTALL_TEST']; ?>" /><?php

	if ($passed['db'] && $passed['files'])
	{

?>&nbsp;&nbsp; <input class="mainoption" name="submit" type="submit" value="<?php echo $lang['INSTALL_NEXT']; ?>" /><?php

	}

?></td>
	</tr>
</table></form>

<?php

	inst_page_footer();
	exit;

}


// Second stage installation
//
// The basic tests have been passed so now we will proceed with asking
// the user for detailed information on their database, server, etc.
if ($stage == 1)
{
	// If the user has decided to test the connection to their database
	// then give it a go
	if (isset($_POST['testdb']))
	{
		// Let's try and load the required module if need be
		if (!@extension_loaded($available_dbms[$dbms]['MODULE']))
		{
			if (!can_load_dll($available_dbms[$dbms]['MODULE']))
			{
				$error['db'][] = $lang['INST_ERR_NO_DB'];;
			}
		}

		connect_check_db(true, $error, $dbms, $table_prefix, $dbhost, $dbuser, $dbpasswd, $dbname, $dbport);
	}


	$available_dbms_temp = array();
	foreach ($available_dbms as $type => $dbms_ary)
	{
		if (!extension_loaded($dbms_ary['MODULE']))
		{
			if (!can_load_dll($dbms_ary['MODULE']))
			{
				continue;
			}
		}

		$available_dbms_temp[$type] = $dbms_ary;
	}

	$available_dbms = &$available_dbms_temp;

	// Here we guess at some server information, however we only
	// do this if no "errors" exist ... if they do then the user
	// has relady set the info and we can bypass it
	if (!sizeof($error))
	{
		if (!empty($_SERVER['SERVER_NAME']) || !empty($_ENV['SERVER_NAME']))
		{
			$server_name = (!empty($_SERVER['SERVER_NAME'])) ? $_SERVER['SERVER_NAME'] : $_ENV['SERVER_NAME'];
		}
		else if (!empty($_SERVER['HTTP_HOST']) || !empty($_ENV['HTTP_HOST']))
		{
			$server_name = (!empty($_SERVER['HTTP_HOST'])) ? $_SERVER['HTTP_HOST'] : $_ENV['HTTP_HOST'];
		}
		else
		{
			$server_name = '';
		}

		if (!empty($_SERVER['SERVER_PORT']) || !empty($_ENV['SERVER_PORT']))
		{
			$server_port = (!empty($_SERVER['SERVER_PORT'])) ? $_SERVER['SERVER_PORT'] : $_ENV['SERVER_PORT'];
		}
		else
		{
			$server_port = '80';
		}

		$script_path = preg_replace('#install\/install\.' . $phpEx . '#i', '', $_SERVER['PHP_SELF']);

		if (isset($_SERVER['HTTPS']))
		{
			$cookie_secure = '1';
		}
		else
		{
			$cookie_secure = '0';
		}

		$domain_name = explode('.', $server_name);
		$domain_count = count($domain_name);

		if (ip2long($server_name) != -1)
		{
			$cookie_domain = $server_name;
			$cookie_name = 'r3born_site';
		}
		elseif ($domain_count < 3)
		{
			$cookie_domain = $server_name;
			$cookie_name = substr($domain_name[0],0,10) . '_site';
		}
		elseif ($domain_count > 3)
		{
			$cookie_domain = '.' . $domain_name[$domain_count - 3] . '.' . $domain_name[$domain_count - 2] . '.' . $domain_name[$domain_count - 1];
			$cookie_name = substr($domain_name[$domain_count - 3],0,10) . '_site';
		}
		else
		{
			$cookie_domain = '.' . $domain_name[$domain_count - 2] . '.' . $domain_name[$domain_count - 1];
			$cookie_name = substr($domain_name[$domain_count - 2],0,10) . '_site';
		}

		$cookie_path = substr($script_path, 0, -1);
		if (strlen($cookie_path) == 0)
		{
  			$cookie_path = '/';
		}
		
		//Overriding the cookie_domain with a safer default.		
		$cookie_domain = '';				
	}

	// Generate list of available DB's
	$dbms_options = '';
	foreach ($available_dbms as $dbms_name => $details)
	{
		$selected = ($dbms_name == $dbms) ? ' selected="selected"' : '';
		$dbms_options .= '<option value="' . $dbms_name . '"' . $selected .'>' . $details['LABEL'] . '</option>';
	}

	$s_hidden_fields = '<input type="hidden" name="stage" value="2" />';
	$s_hidden_fields .= ($img_imagick) ? '<input type="hidden" name="img_imagick" value="' . addslashes($img_imagick) . '" />' : '';

	inst_page_header($lang['WELCOME_INSTALL']);

?>
<form action="<?php echo "install.$phpEx"; ?>" name="installation" method="post">
<h1><?php echo $lang['INITIAL_CONFIG']; ?></h1>

<p><?php echo $lang['INITIAL_CONFIG_EXPLAIN']; ?></p>

<table width="100%" cellspacing="1" cellpadding="2" border="0" class="forumline">
	<tr>
		<th colspan="2"><?php echo $lang['ADMIN_CONFIG']; ?></th>
	</tr>
<?php

	if (isset($error['admin']) && sizeof($error['admin']))
	{
?>
	<tr>
		<td class="row3" colspan="2" align="center"><span class="gen" style="color:red"><?php echo implode('<br />', $error['admin']); ?></span></td>
	</tr>
<?php

	}
?>
	<tr>
		<td class="row1" width="50%">
			<b><?php echo $lang['DEFAULT_LANG']; ?>:</b>
		</td>
		<td class="row2"><select name="lang"><?php echo inst_language_select($language); ?></select></td>
	</tr>
	<tr>
		<td class="row1" width="50%">
			<b><?php echo $lang['ADMIN_USERNAME']; ?>:</b>
		</td>
		<td class="row2"><input class="post" type="text" name="admin_name" value="<?php echo ($admin_name != '') ? $admin_name : ''; ?>" /></td>
	</tr>
	<tr>
		<td class="row1" width="50%">
			<b><?php echo $lang['CONTACT_EMAIL']; ?>:</b>
		</td>
		<td class="row2"><input class="post" type="text" name="board_email1" value="<?php echo ($board_email1 != '') ? $board_email1 : ''; ?>" /></td>
	</tr>
	<tr>
		<td class="row1" width="50%">
			<b><?php echo $lang['CONTACT_EMAIL_CONFIRM']; ?>:</b>
		</td>
		<td class="row2"><input class="post" type="text" name="board_email2" value="<?php echo ($board_email2 != '') ? $board_email2 : ''; ?>" /></td>
	</tr>
	<tr>
		<td class="row1" width="50%">
			<b><?php echo $lang['ADMIN_PASSWORD']; ?>:</b>
		</td>
		<td class="row2"><input class="post" type="password" name="admin_pass1" value="<?php echo ($admin_pass1 != '') ? $admin_pass1 : ''; ?>" /></td>
	</tr>
	<tr>
		<td class="row1" width="50%">
			<b><?php echo $lang['ADMIN_PASSWORD_CONFIRM']; ?>:</b>
		</td>
		<td class="row2"><input class="post" type="password" name="admin_pass2" value="<?php echo ($admin_pass2 != '') ? $admin_pass2 : ''; ?>" /></td>
	</tr>
	<tr>
		<th colspan="2"><?php echo $lang['DB_CONFIG']; ?></th>
	</tr>
<?php

	if (isset($error['db']) && sizeof($error['db']))
	{
?>
	<tr>
		<td class="row3" colspan="2" align="center"><span class="gen" style="color:red"><?php echo implode('<br />', $error['db']); ?></span></td>
	</tr>
<?php

	}
?>
	<tr>
		<td class="row1" width="50%">
			<b><?php echo $lang['DBMS']; ?>:</b></td>
		<td class="row2"><select name="dbms" onchange="if (document.install_form.upgrade.options[upgrade.selectedIndex].value == 1) { document.install_form.dbms.selectedIndex=0}"><?php echo $dbms_options; ?></select></td>
	</tr>
	<tr>
		<td class="row1" width="50%">
			<b><?php echo $lang['DB_HOST']; ?>:</b><br />
			<span class="gensmall"><?php echo $lang['DB_HOST_EXPLAIN']; ?></span>
		</td>
		<td class="row2"><input class="post" type="text" name="dbhost" value="<?php echo ($dbhost != '') ? $dbhost : ''; ?>" /></td>
	</tr>
	<tr>
		<td class="row1" width="50%">
			<b><?php echo $lang['DB_PORT']; ?>:</b><br />
			<span class="gensmall"><?php echo $lang['DB_PORT_EXPLAIN']; ?></span>
		</td>
		<td class="row2"><input class="post" type="text" name="dbport" value="<?php echo ($dbport != '') ? $dbport : ''; ?>" /></td>
	</tr>
	<tr>
		<td class="row1" width="50%">
			<b><?php echo $lang['DB_NAME']; ?>: </b>
		</td>
		<td class="row2"><input class="post" type="text" name="dbname" value="<?php echo ($dbname != '') ? $dbname : ''; ?>" /></td>
	</tr>
	<tr>
		<td class="row1" width="50%">
			<b><?php echo $lang['DB_USERNAME']; ?>:</b>
		</td>
		<td class="row2"><input class="post" type="text" name="dbuser" value="<?php echo ($dbuser != '') ? $dbuser : ''; ?>" /></td>
	</tr>
	<tr>
		<td class="row1" width="50%">
			<b><?php echo $lang['DB_PASSWORD']; ?>:</b>
		</td>
		<td class="row2"><input class="post" type="password" name="dbpasswd" value="<?php echo ($dbpasswd != '') ? $dbpasswd : ''; ?>" /></td>
	</tr>
	<tr>
		<td class="row1" width="50%">
			<b><?php echo $lang['TABLE_PREFIX']; ?>:</b>
		</td>
		<td class="row2"><input class="post" type="text" name="table_prefix" value="<?php echo (!empty($table_prefix)) ? $table_prefix : 'r3born_'; ?>" /></td>
	</tr>
	<tr>
		<th colspan="2"><?php echo $lang['SERVER_CONFIG']; ?></th>
	</tr>
<?php

	if (isset($error['server']) && sizeof($error['server']))
	{
?>
	<tr>
		<td class="row3" colspan="2" align="center"><span class="gen" style="color:red"><?php echo implode('<br />', $error['server']); ?></span></td>
	</tr>
<?php

	}
?>
	<tr>
		<td class="row1" width="50%">
			<b><?php echo $lang['SERVER_NAME']; ?>:</b>
		</td>
		<td class="row2"><input class="post" type="text" name="server_name" value="<?php echo $server_name; ?>" /></td>
	</tr>
	<tr>
		<td class="row1" width="50%">
			<b><?php echo $lang['SERVER_PORT']; ?>:</b>
		</td>
		<td class="row2"><input class="post" type="text" name="server_port" value="<?php echo $server_port; ?>" /></td>
	</tr>
	<tr>
		<td class="row1" width="50%">
			<b><?php echo $lang['SCRIPT_PATH']; ?>:</b>
		</td>
		<td class="row2"><input class="post" type="text" name="script_path" value="<?php echo $script_path; ?>" /></td>
	</tr>
	<tr>
		<th colspan="2"><?php echo $lang['Cookie_settings']; ?></th>
	</tr>
<?php

	if (isset($error['cookie']) && sizeof($error['cookie']))
	{
?>
	<tr>
		<td class="row3" colspan="2" align="center"><span class="gen" style="color:red"><?php echo implode('<br />', $error['cookie']); ?></span></td>
	</tr>
<?php

	}
?>

	<tr>
		<td class="row1" width="50%">
			<b><?php echo $lang['Cookie_secure']; ?>:</b><br />
			<span class="gensmall"><?php echo $lang['Cookie_secure_explain']; ?></span>
		</td>
		<td class="row2" valign="top">
			<span class="gen">
			<input type="radio" name="cookie_secure" value="0" <?php echo ($cookie_secure == '0') ? 'checked="checked" ' : ''; ?>/> <?php echo $lang['Disabled']; ?>&nbsp;&nbsp;<input type="radio" name="cookie_secure" value="1" <?php echo ($cookie_secure == '1') ? 'checked="checked" ' : ''; ?>/> <?php echo $lang['Enabled']; ?>
			</span>
		</td>
	</tr>
	<tr>
		<td class="row1" width="50%">
			<b><?php echo $lang['Cookie_domain']; ?>:</b><br />
			<span class="gensmall"><?php echo $lang['Cookie_domain_explain']; ?></span>
		</td>
		<td class="row2" valign="top"><input class="post" type="text" maxlength="255" name="cookie_domain" value="<?php echo $cookie_domain; ?>" /></td>
	</tr>
	<tr>
		<td class="row1" width="50%">
			<b><?php echo $lang['Cookie_path']; ?>:</b><br />
			<span class="gensmall"><?php echo $lang['Cookie_path_explain']; ?></span>
		</td>
		<td class="row2" valign="top"><input class="post" type="text" maxlength="255" name="cookie_path" value="<?php echo $cookie_path; ?>" /></td>
	</tr>
	<tr>
		<td class="row1" width="50%">
			<b><?php echo $lang['Cookie_name']; ?>:</b><br />
			<span class="gensmall"><?php echo $lang['Cookie_name_explain']; ?></span>
		</td>
		<td class="row2" valign="top"><input class="post" type="text" maxlength="16" name="cookie_name" value="<?php echo $cookie_name; ?>" /></td>
	</tr>
	<tr>
		<td class="cat" colspan="2" align="center"><?php echo $s_hidden_fields; ?><input class="mainoption" name="install" type="submit" value="<?php echo $lang['INSTALL_START']; ?>" /></td>
	</tr>
</table></form>
<?php

	inst_page_footer();
	exit;
}


// Third stage
//
// Here we attempt to write out the config file. If we cannot write it directly
// we'll offer the user various options
if ($stage == 2)
{
	// Here we are checking to see one final time which modules
	// we need to load and whether we can load them. This includes
	// modules in addition to that required by the DB layer
	$load_extensions = array();
	$check_exts = array_merge(array($available_dbms[$dbms]['MODULE']), $php_dlls_other);

	foreach ($check_exts as $dll)
	{
		if (!extension_loaded($dll))
		{
			if (!can_load_dll($dll))
			{
				continue;
			}
			$load_extensions[] = "$dll.$suffix";
		}
	}

	$load_extensions = implode(',', $load_extensions);

	// Define the contents of config.php
	$config_data = "<?php\n";
	$config_data .= "// Auto-generated config file\n// Do not change anything in this file!\n";
	$config_data .= "\$dbms = '$dbms';\n";
	$config_data .= "\$dbhost = '$dbhost';\n";
	$config_data .= "\$dbport = '$dbport';\n";
	$config_data .= "\$dbname = '$dbname';\n";
	$config_data .= "\$dbuser = '$dbuser';\n";
	$config_data .= "\$dbpasswd = '$dbpasswd';\n\n";
	$config_data .= "\$table_prefix = '$table_prefix';\n";
//	$config_data .= "\$acm_type = '" . (($acm_type) ? $acm_type : 'file') . "';\n";
//	$config_data .= "\$acm_type = 'file';\n";
//	$config_data .= "\$load_extensions = '$load_extensions';\n\n";
	$config_data .= "define('R3BORN_INSTALLED', true);\n";
	$config_data .= "define('DEBUG', true);\n"; // Comment out when final
	$config_data .= "//define('DEBUG_EXTRA', true);\n";	
	$config_data .= '?' . '>'; // Done this to prevent highlighting editors getting confused!

	// Attempt to write out the config directly ...
	if (filesize($root_path . 'config.' . $phpEx) == 0 && is_writeable($root_path . 'config.' . $phpEx))
	{
		// Lets jump to the DB setup stage ... if nothing goes wrong below
		$stage = 3;

		if (!($fp = @fopen($root_path . 'config.'.$phpEx, 'w')))
		{
			// Something went wrong ... so let's try another method
			$stage = 2;
		}

		if (!(@fwrite($fp, $config_data)))
		{
			// Something went wrong ... so let's try another method
			$stage = 2;
		}

		@fclose($fp);
	}

	// We couldn't write it directly so we'll give the user three alternatives
	if ($stage == 2)
	{
		$ignore_ftp = false;

		// User is trying to upload via FTP ... so let's process it
		if (isset($_POST['sendftp']))
		{
			if (($conn_id = @ftp_connect('localhost')))
			{
				if (@ftp_login($conn_id, $ftp_user, $ftp_pass))
				{
					// Write out a temp file ... if safe mode is on we'll write it to our
					// local cache/tmp directory
					$tmp_path = (!@ini_get('safe_mode')) ? false : $root_path . 'cache/tmp';
					$filename = tempnam($tmp_path, unique_id() . 'cfg');

					$fp = @fopen($filename, 'w');
					@fwrite($fp, $config_data);
					@fclose($fp);

					if (@ftp_chdir($conn_id, $ftp_dir))
					{
						// So far, so good so now we'll try and upload the file. If it
						// works we'll jump to stage 3, else we'll fall back again
						if (@ftp_put($conn_id, 'config.' . $phpEx, $filename, FTP_ASCII))
						{
							$stage = 3;
						}
						else
						{
							// Since we couldn't put the file something is fundamentally wrong, e.g.
							// the file is owned by a different user, etc. We'll give up trying
							// FTP at this point
							$ignore_ftp = true;
						}
					}
					else
					{
						$error['ftp'][] = $lang['INST_ERR_FTP_PATH'];
					}

					// Remove the temporary file now
					@unlink($filename);
				}
				else
				{
					$error['ftp'][] = $lang['INST_ERR_FTP_LOGIN'];
				}
				@ftp_quit($conn_id);
			}
		}
		else if (isset($_POST['dlftp']))
		{
			// The user requested a download, so send the relevant headers
			// and dump out the data
			header("Content-Type: text/x-delimtext; name=\"config.$phpEx\"");
			header("Content-disposition: attachment; filename=config.$phpEx");
			echo $config_data;
			exit;
		}

		// Here we give the users up to three options to complete the setup
		// of config.php, FTP, download and a retry and direct writing
		if ($stage == 2)
		{
			inst_page_header($lang['WELCOME_INSTALL']);
?>

<form action="<?php echo "install.$phpEx"; ?>" name="installation" method="post">
<p><?php echo $lang['INSTALL_SEND_CONFIG']; ?></p>

<?php

			$s_hidden_fields = '<input type="hidden" name="stage" value="2" />';
			$s_hidden_fields .= '<input type="hidden" name="dbms" value="' . $dbms . '" />';
			$s_hidden_fields .= '<input type="hidden" name="table_prefix" value="' . $table_prefix . '" />';
			$s_hidden_fields .= '<input type="hidden" name="dbhost" value="' . $dbhost . '" />';
			$s_hidden_fields .= '<input type="hidden" name="dbport" value="' . $dbport . '" />';
			$s_hidden_fields .= '<input type="hidden" name="dbname" value="' . $dbname . '" />';
			$s_hidden_fields .= '<input type="hidden" name="dbuser" value="' . $dbuser . '" />';
			$s_hidden_fields .= '<input type="hidden" name="dbpasswd" value="' . $dbpasswd . '" />';
			$s_hidden_fields .= '<input type="hidden" name="admin_name" value="' . $admin_name . '" />';
			$s_hidden_fields .= '<input type="hidden" name="admin_pass1" value="' . $admin_pass1 . '" />';
			$s_hidden_fields .= '<input type="hidden" name="admin_pass2" value="' . $admin_pass2 . '" />';
			$s_hidden_fields .= '<input type="hidden" name="server_port" value="' . $server_port . '" />';
			$s_hidden_fields .= '<input type="hidden" name="server_name" value="' . $server_name . '" />';
			$s_hidden_fields .= '<input type="hidden" name="script_path" value="' . $script_path . '" />';
			$s_hidden_fields .= '<input type="hidden" name="board_email1" value="' . $board_email1 . '" />';
			$s_hidden_fields .= '<input type="hidden" name="board_email2" value="' . $board_email2 . '" />';
			$s_hidden_fields .= '<input type="hidden" name="language" value="' . $language . '" />';

			$s_hidden_fields .= '<input type="hidden" name="cookie_secure" value="'.$cookie_secure.'" />';
			$s_hidden_fields .= '<input type="hidden" name="cookie_domain" value="'.$cookie_domain.'" />';
			$s_hidden_fields .= '<input type="hidden" name="cookie_name" value="'.$cookie_name.'" />';
			$s_hidden_fields .= '<input type="hidden" name="cookie_path" value="'.$cookie_path.'" />';

			// Can we ftp? If we can then let's offer that option on top of download
			// We first see if the relevant extension is loaded and then whether a server is
			// listening on the ftp port
			if (extension_loaded('ftp') && ($fsock = @fsockopen('localhost', 21, $errno, $errstr, 1)) && !$ignore_ftp)
			{
				@fclose($fsock);

?>

<h1><?php echo $lang['FTP_CONFIG']; ?></h1>

<p><?php echo $lang['FTP_CONFIG_EXPLAIN']; ?></p>

<table width="100%" cellspacing="1" cellpadding="2" border="0" class="forumline">
	<tr>
		<th colspan="2">&nbsp;</th>
	</tr>
<?php

				if (sizeof($error['ftp']))
				{

?>
	<tr>
		<td class="row3" colspan="2" align="center"><span class="gen" style="color:red"><?php echo implode('<br />', $error['ftp']); ?></span></td>
	</tr>
<?php

				}

?>
	<tr>
		<td class="row1" width="50%">
			<b><?php echo $lang['FTP_PATH']; ?>: </b><br />
			<span class="gensmall"><?php echo $lang['FTP_PATH_EXPLAIN']; ?></span>
		</td>
		<td class="row2"><input class="post" type="text" name="ftp_dir" size="40" maxlength="255" value="<?php echo $ftp_dir; ?>" /></td>
	</tr>
	<tr>
		<td class="row1" width="50%">
			<b><?php echo $lang['FTP_USERNAME']; ?>: </b>
		</td>
		<td class="row2"><input class="post" type="text" name="ftp_user" size="40" maxlength="255" value="<?php echo $ftp_user; ?>" ></td>
	</tr>
	<tr>
		<td class="row1" width="50%">
			<b><?php echo $lang['FTP_PASSWORD']; ?>: </b>
		</td>
		<td class="row2"><input class="post" type="password" name="ftp_pass" size="40" maxlength="255" value="<?php echo $ftp_pass; ?>" ></td>
	</tr>
	<tr>
		<td class="cat" colspan="2" align="center"><input class="mainoption" name="sendftp" type="submit" value="<?php echo $lang['FTP_UPLOAD']; ?>" /></td>
	</tr>
</table>

<br />

<?php

			}

?>

<h1><?php echo $lang['DL_CONFIG']; ?></h1>

<p><?php echo $lang['DL_CONFIG_EXPLAIN']; ?></p>

<table width="100%" cellspacing="1" cellpadding="2" border="0" class="forumline">
	<tr>
		<td class="cat" align="center"><input class="mainoption" name="dlftp" type="submit" value="<?php echo $lang['DL_DOWNLOAD']; ?>" />&nbsp;&nbsp;<input class="mainoption" name="dldone" type="submit" value="<?php echo $lang['DL_DONE']; ?>" /></td>
	</tr>
</table>

<br />

<h1><?php echo $lang['RETRY_WRITE']; ?></h1>

<p><?php echo $lang['RETRY_WRITE_EXPLAIN']; ?></p>

<table width="100%" cellspacing="1" cellpadding="2" border="0">
	<tr>
		<td class="cat" align="center"><input class="mainoption" name="retry" type="submit" value="<?php echo $lang['CONFIG_RETRY']; ?>" /></td>
	</tr>
</table>

<?php echo $s_hidden_fields; ?></form>

<?php

			inst_page_footer();
			exit;

		}
	}
}


// Everything should now be in place so we'll go ahead with the actual
// setup of the database. Hopefully nothing will go wrong from this
// point on ... it really shouldn't
if ($stage == 3)
{
	// If we get here and the extension isn't loaded we know that we
	// can go ahead and load it without fear of failure ... probably
	if (!extension_loaded($available_dbms[$dbms]['MODULE']))
	{
		@dl($available_dbms[$dbms]['MODULE'] . ".$prefix");
	}

	require($root_path . 'includes/db/' . $dbms . '.' . $phpEx);

	// Make the database connection.
	$db = new sql_db($dbhost, $dbuser, $dbpasswd, $dbname, false);
	if(!$db->db_connect_id)
	{
		message_die(CRITICAL_ERROR, 'Could not connect to the database');
	}

	$dbms_schema = 'schemas/' . $available_dbms[$dbms]['SCHEMA'] . '_schema.sql';

	$dbms_basic = 'schemas/schema_data.sql';

	$remove_remarks = $available_dbms[$dbms]['COMMENTS'];;
	$delimiter = $available_dbms[$dbms]['DELIM'];
	$delimiter_basic = $available_dbms[$dbms]['DELIM_BASIC'];	

	// Ok we have the db info go ahead and read in the relevant schema
	// and work on building the table.. probably ought to provide some
	// kind of feedback to the user as we are working here in order
	// to let them know we are actually doing something.

	$sql_query = @fread(@fopen($dbms_schema, 'r'), @filesize($dbms_schema));

	$sql_query = preg_replace('#r3born_#i', $table_prefix, $sql_query);

	$sql_query = $remove_remarks($sql_query);
	$sql_query = split_sql_file($sql_query, $delimiter);

	for ($i = 0; $i < sizeof($sql_query); $i++)
	{
		if (trim($sql_query[$i]) != '')
		{
			if (!($result = $db->sql_query($sql_query[$i])))
			{
				$error = $db->sql_error();
				inst_db_error($error['message'], $sql, __LINE__, __FILE__);
			}
		}
	}
	unset($sql_query);

	// Ok tables have been built, let's fill in the basic information
	$sql_query = @fread(@fopen($dbms_basic, 'r'), @filesize($dbms_basic));

	// Deal with any special comments
	switch ($dbms)
	{
		case 'mssql':
		case 'mssql_odbc':
			$sql_query = preg_replace('#\# MSSQL IDENTITY (r3born_[a-z_]+) (ON|OFF) \##s', 'SET IDENTITY_INSERT \1 \2;', $sql_query);
			break;
		case 'postgres':
			$sql_query = preg_replace('#\# POSTGRES (BEGIN|COMMIT) \##s', '\1; ', $sql_query);
			break;
	}

	$sql_query = preg_replace('#r3born_#i', $table_prefix, $sql_query);

	if ($remove_remarks)
	{
		$sql_query = $remove_remarks($sql_query);
    }

	$sql_query = split_sql_file($sql_query, $delimiter_basic);

	for($i = 0; $i < sizeof($sql_query); $i++)
	{
		if (trim($sql_query[$i]) != '')
		{
			if (!($result = $db->sql_query($sql_query[$i])))
			{
				$error = $db->sql_error();
				inst_db_error($error['message'], $sql, __LINE__, __FILE__);
			}
		}
	}
	unset($sql_query);

	// Ok at this point they have entered their admin password, let's go
	// ahead and create the admin account with some basic default information
    // that they can customize later, and write out the config file.  After
	// this we are going to pass them over to the admin_forum.php script
	// to set up their forum defaults.
	$error = '';

	// Update the default admin user with their information.

	$sql = "INSERT INTO " . $table_prefix . "config (config_name, config_value)
		VALUES ('board_startdate', " . time() . ")";
	if (!$db->sql_query($sql))
	{
		$error .= "Could not insert board_startdate :: " . $sql . " :: " . __LINE__ . " :: " . __FILE__ . "<br /><br />";
	}

	$sql = "INSERT INTO " . $table_prefix . "config (config_name, config_value)
		VALUES ('default_lang', '" . str_replace("\'", "''", $language) . "')";
	if (!$db->sql_query($sql))
	{
		$error .= "Could not insert default_lang :: " . $sql . " :: " . __LINE__ . " :: " . __FILE__ . "<br /><br />";
	}

	$update_config = array(
		'board_email'	=> $board_email1,
		'script_path'	=> $script_path,
		'server_port'	=> $server_port,
		'server_name'	=> $server_name,
		'cookie_secure' => $cookie_secure,
		'cookie_domain' => $cookie_domain,
		'cookie_name'   => $cookie_name,
		'cookie_path'   => $cookie_path,
	);

	while (list($config_name, $config_value) = each($update_config))
	{
		$sql = "UPDATE " . $table_prefix . "config
			SET config_value = '$config_value'
			WHERE config_name = '$config_name'";
		if (!$db->sql_query($sql))
		{
			$error .= "Could not insert default_lang :: " . $sql . " :: " . __LINE__ . " :: " . __FILE__ . "<br /><br />";
		}
	}

	$admin_pass_md5 = ($confirm && $userdata['user_level'] == 1) ? $admin_pass1 : md5($admin_pass1);

	$sql = "UPDATE " . $table_prefix . "users
		SET username = '" . str_replace("\'", "''", $admin_name) . "', user_password='" . str_replace("\'", "''", $admin_pass_md5) . "', user_lang = '" . str_replace("\'", "''", $language) . "', user_email='" . str_replace("\'", "''", $board_email1) . "'
		WHERE username = 'Admin'";
	if (!$db->sql_query($sql))
	{
		$error .= "Could not update admin info :: " . $sql . " :: " . __LINE__ . " :: " . __FILE__ . "<br /><br />";
	}

	$sql = "UPDATE " . $table_prefix . "users
		SET user_regdate = " . time();
	if (!$db->sql_query($sql))
	{
		$error .= "Could not update user_regdate :: " . $sql . " :: " . __LINE__ . " :: " . __FILE__ . "<br /><br />";
	}

	if ($error != '')
	{
		inst_db_error($error['message'], $sql, __LINE__, __FILE__);
	}

	$stage = 4;
}

// Install completed ... log the user in ... we're done
if ($stage == 4)
{
	/* Load the basic configuration data
	define('DELETED', -1);
	define('ANONYMOUS', -1);

	define('USER', 0);
	define('ADMIN', 1);
	define('MOD', 2);

	define('GENERAL_MESSAGE', 200);
	define('GENERAL_ERROR', 202);
	define('CRITICAL_MESSAGE', 203);
	define('CRITICAL_ERROR', 204);

	define('PAGE_INDEX', 0);

	define('BANLIST_TABLE', $table_prefix.'banlist');
	define('CONFIG_TABLE', $table_prefix.'config');
	define('GROUPS_TABLE', $table_prefix.'groups');
	define('SESSIONS_TABLE', $table_prefix.'sessions');
	define('SESSIONS_KEYS_TABLE', $table_prefix.'sessions_keys');
	define('THEMES_TABLE', $table_prefix.'themes');
	define('USERS_TABLE', $table_prefix.'users');

	$sql = "SELECT *
		FROM {$table_prefix}config";
	$result = $db->sql_query($sql);

	$config = array();
	while ($row = $db->sql_fetchrow($result))
	{
		$config[$row['config_name']] = $row['config_value'];
	}
	$db->sql_freeresult($result);

	//$user->session_begin();
	//$auth->login($admin_name, $admin_pass1);



	$userdata = session_pagestart($user_ip, PAGE_INDEX);
	init_userprefs($userdata);
	*/

	inst_page_header($lang['WELCOME_INSTALL']);

?>
<form action="<?php echo "install.$phpEx"; ?>" name="installation" method="post">
<h1 align="center"><?php echo $lang['INSTALL_CONGRATS']; ?></h1>


<p><?php echo $lang['INSTALL_CONGRATS_EXPLAIN']; ?></p>

<a href="<?php echo "../index.$phpEx"; ?>"><h2 align="center"><?php echo $lang['INSTALL_LOGIN']; ?></h2></a>

<?php

	inst_page_footer();
	exit;

}

exit;

?>